﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Benchmark_System {
    /// <summary>
    /// Logger class writing to a file
    /// </summary>
    class LoggerTextFile {
        System.IO.StreamWriter StreamW;

        public LoggerTextFile(string file) {
            StreamW = new System.IO.StreamWriter(file);
        }
        
        public void Subscribe(BenchmarkSystem bms) {
            bms.JobSubmitted += OnJobSubmitted;
            bms.JobCancelled += OnJobCancelled;
            bms.JobRunning += OnJobRunning;
            bms.JobTerminated += OnJobTerminated;
            bms.JobFailed += OnJobFailed;
        }

        internal void OnJobSubmitted(object sender, EventArgs ea) {
            StreamW.WriteLine("Job submitted");
            StreamW.Flush();
        }

        internal void OnJobCancelled(object sender, EventArgs ea) {
            StreamW.WriteLine("Job cancelled");
            StreamW.Flush();
        }

        internal void OnJobRunning(object sender, EventArgs ea) {
            StreamW.WriteLine("Job running");
            StreamW.Flush();
        }

        internal void OnJobTerminated(object sender, EventArgs ea) {
            StreamW.WriteLine("Job terminated");
            StreamW.Flush();
        }

        internal void OnJobFailed(object sender, EventArgs ea) {
            StreamW.WriteLine("Job failed");
            StreamW.Flush();
        }
    }
}

